package cn.bdqn.t354.mapper;

import cn.bdqn.t354.pojo.SysUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SysUserMapperTester {
    @Resource
    SysUserMapper sysUserMapper;

    @Test
    public void testWarpperEq(){
        //角色id等于2
        QueryWrapper qw=new QueryWrapper();
        qw.eq("usr_role_id",2);

        List<SysUser> list = sysUserMapper.selectList(qw);
        for (SysUser o : list) {
            System.out.println(o);
        }
    }

    @Test
    public void testWarpperLike(){
        //角色id等于2
        QueryWrapper qw=new QueryWrapper();
        //包含
//        qw.like("usr_name","d");
        //以什么开头
//        qw.likeRight("usr_name","d");
        //以什么结尾
        qw.likeLeft("usr_name","d");
        List<SysUser> list = sysUserMapper.selectList(qw);
        for (SysUser o : list) {
            System.out.println(o);
        }
    }

    @Test
    public void testWarpperRange(){
        //角色id等于2
        QueryWrapper qw=new QueryWrapper();
//        qw.ge("usr_id",1);
//        qw.le("usr_id",10);

        qw.between("usr_id",1,10);

        List<SysUser> list = sysUserMapper.selectList(qw);
        for (SysUser o : list) {
            System.out.println(o);
        }
    }

    @Test
    public void testWarpperOrder(){
        //角色id等于2
        QueryWrapper qw=new QueryWrapper();
//        qw.orderByDesc("usr_id");
        qw.orderBy(true,false,"usr_id");

        List<SysUser> list = sysUserMapper.selectList(qw);
        for (SysUser o : list) {
            System.out.println(o);
        }
    }

    @Test
    public void testWarpperConditions(){
        //角色id等于2
        QueryWrapper qw=new QueryWrapper();
        qw.eq("usr_name","dajun");
        qw.eq("usr_password","123456");

        SysUser sysUser = sysUserMapper.selectOne(qw);
        System.out.println(sysUser);
    }

    @Test
    public void testWarpperPage(){
        Page page=new Page(1,2);
        sysUserMapper.selectPage(page, null);
        System.out.println("当前第几页："+page.getCurrent());
        System.out.println("每页显示多少条："+page.getSize());
        System.out.println("总共多少条记录："+page.getTotal());
        System.out.println("总共多少页："+page.getPages());
        System.out.println("当前页显示的数据："+page.getRecords());
    }

}
